<template>
  <div>
      <el-dialog   :modelValue="dialogVisible"  title="增加映射"  width="50%"
                  :close-on-click-modal="false" :close-on-press-escape="false"
                  :show-close="false" >

        <el-form :model="item" label-width="120px"   >
          <el-form-item label="值" >
            <el-input v-model="item.value"  style="width: 80%"></el-input>
          </el-form-item>
          <el-form-item label="映射画面">
            <el-input v-model="item.picpath"  style="width: 80%"></el-input>
            <el-button @click="handleSelectFile" >选择文件</el-button>
          </el-form-item>
        </el-form>
        <DlgBackPicFile :dialogVisible="dlgvisible" :config-new-file="isConfigNewFile" @res-file="handleResFile"></DlgBackPicFile>

        <template #footer>
          <div style="display: flex; flex-direction: row-reverse; ">
            <el-button @click="handleCancel">取消</el-button>
            <el-button type="primary" @click="handleOk"  style="margin: 0 10px 0 10px;" >确定</el-button>
          </div>
        </template>
      </el-dialog>
  </div>
</template>

<script>

import {ElMessage} from "element-plus";
import DlgBackPicFile from "@/draw/drwfile/DlgBackPicFile.vue";

export default {
  name: "DlgAddMap",
  props:{ dialogVisible: Boolean },
  components:{DlgBackPicFile},
  emits:[ "resAddMap" ],

  mounted() {

  },
  computed:{

  },
  data(){
    return{
      item : { value: 0, picpath: "images/1G_stop.svg" },
      dlgvisible: false,  
      isConfigNewFile : false ,
    }
  },
  watch: {

  },
  methods:{
    init( dat ){
      this.item = JSON.parse( JSON.stringify(dat)  )
    },

    handleOk(  ){
      this.$emit( "resAddMap", 1, this.item )
    },

    handleCancel(){
      this.$emit( "resAddMap", 0, this.item  )
    },

    handleSelectFile( ){
        this.dlgvisible = true 
    },  

    handleResFile( code, res  ){
      if( code === 0 ) {
        this.dlgvisible = false 
        return
      }

      if ( res.dir === "/" )
        this.item.picpath = "images" + res.dir + res.filename
      else
        this.item.picpath = "images" + res.dir + "/" + res.filename
      this.dlgvisible = false 
        
    },

  },  // end of methods

}

</script>

<style  lang="less" scoped >

// ::v-deep(.el-dialog){
//   .el-dialog__body {
//       height: 50vh; overflow: auto; padding: 0px;
//   }

//   .el-dialog__header{
//     margin: 0;
//     background-color: @dialog_header_color;
//   }

//   .el-dialog__footer {
//     background-color: @dialog_footer_color;
//   }
// }

::v-deep( tbody tr:hover > td ){
  background-color: transparent !important;
}

</style>